﻿import React from 'react';
import { Form, Icon, message, Row, Col, Spin, Button, Input, Date, DatePicker, TimePicker, Tooltip  } from 'antd';
import { connect } from 'react-redux'
import { hashHistory } from 'react-router'
import './index.css'
import { companyNotify, companyNotifyClear } from '../../actions'
import moment from 'moment';
const FormItem = Form.Item;

/**
 * 定义Header组件, 包括登录/注销的链接, 以及一些自定义链接
 */
class StudentNotify extends React.Component {

  constructor(props){
    super(props);
  }

  componentWillUnmount () {
    this.props.dispatch(companyNotifyClear()());
  }

  onSubmitHandle(e) {
    this.props.form.validateFieldsAndScroll((errors, values) => {
      if (!!errors) {
        console.log('Errors in form!!!');
        return;
      }
      console.log('Submit!!!');
      this.props.dispatch(companyNotify.request()({...values, type:'student'}));
    });
  }

  render() {
    let { getFieldDecorator } = this.props.form;
    let { loading, success } = this.props;
    console.log('loading=', loading);
    const format = 'HH:mm';
    return (
      <div style={{ marginTop: 16, minHeight: 560 }}>
        <Spin spinning={loading}>
          <Form horizontal>
            <FormItem label="主题" labelCol={{ span: 6 }} wrapperCol={{ span: 14 }} >
              {getFieldDecorator('subject', { rules: [{required: true}] })(<Input placeholder="请输入邮件主题" />)}
            </FormItem>

            <FormItem label="邮件内容" labelCol={{ span: 6 }} wrapperCol={{ span: 14 }} >
              {getFieldDecorator('content', { rules: [{required: true}] })(<Input type="textarea" rows="8" placeholder="请输入邮件内容，最多200字"/>)}
            </FormItem>

            <FormItem label="发送日期" labelCol={{ span: 6 }} wrapperCol={{ span: 14 }} >
              {getFieldDecorator('sendDate', { rules: [{required: true}] })(<DatePicker format="YYYY-MM-DD" />)}
            </FormItem>
             <FormItem label="发送时间" labelCol={{ span: 6 }} wrapperCol={{ span: 14 }} >
              {getFieldDecorator('sendTime', { rules: [{required: true}] })(<TimePicker format={format} />)}
            </FormItem>
          </Form>
          <FormItem wrapperCol={{ span: 18, offset: 6 }} style={{ marginTop: 24 }}>
            <Button type="primary" disabled={success} icon="mail" onClick={this.onSubmitHandle.bind(this)} loading={loading}>发送</Button>
            &nbsp;&nbsp;&nbsp;
            <Button>取消</Button>
          </FormItem>
        </Spin>
      </div>
    );
  }

}

StudentNotify = Form.create()(StudentNotify);

function mapStateToProps(state) {
  return {
    loading: state.enterprise.loading,
    success:state.enterprise.success
  };
}

export default connect(mapStateToProps)(StudentNotify)
